#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

void solve() {
  int n, t;
  cin >> n >> t;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  auto check = [&](int x) {
    int sum = 0, res = 0;
    for(auto v : a) {
      if(v > x) {
        return false;
      }
    }
    for(int i = 0; i < n; i++) {
      if(sum + a[i] > x) {
        sum = 0;
        res++;
      }
      sum += a[i];
      sum += b[i];
      if(sum > x) {
        res += (sum / x);
        sum %= x;
      }
    } 
    return res <= t;
  };
  if(!check(3600)) {
    cout << -1 << endl;
    return;
  }
  int l = 1, r = 3600;
  while(l < r) {
    int mid = l + r >> 1;
    if(check(mid)) r = mid;
    else l = mid + 1;
  }
  cout << l << endl;
}

signed main() {
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}